package com.xc.content.enums;

import lombok.Getter;
import lombok.Setter;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * @Author: hyacinth
 * @CreateTime: 2025-01-03
 * @Version: 1.0
 */
@Getter
public enum HttpStatus {
    NOT_FOUND(404, Series.CLIENT_ERROR, "Not Found"),
    CONFLICT(409, Series.CLIENT_ERROR, "数据已存在"),
    SYS_EXCEPTION(500, Series.SERVER_ERROR, "系统异常"),
    DB_EXCEPTION(400, Series.SERVER_ERROR, "请求异常"),
    METHOD_NOT_ALLOWED(405, Series.CLIENT_ERROR, "请求方法不支持"),
    BAD_REQUEST(400, Series.CLIENT_ERROR, "Bad Request");


    private final int value;
    private final Series series;
    private final String reasonPhrase;

    private HttpStatus(int value, Series series, String reasonPhrase) {
        this.value = value;
        this.series = series;
        this.reasonPhrase = reasonPhrase;
    }

    public static HttpStatus valueOf(int statusCode) {
        HttpStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
        } else {
            return status;
        }
    }

    @Nullable
    public static HttpStatus resolve(int statusCode) {
        HttpStatus[] var1 = values();
        int var2 = var1.length;

        for (HttpStatus status : var1) {
            if (status.value == statusCode) {
                return status;
            }
        }

        return null;
    }

    public static enum Series {
        INFORMATIONAL(1),
        SUCCESSFUL(2),
        REDIRECTION(3),
        CLIENT_ERROR(4),
        SERVER_ERROR(5);

        private final int value;

        private Series(int value) {
            this.value = value;
        }

        public int value() {
            return this.value;
        }

        /**
         * @deprecated
         */
        @Deprecated
        public static Series valueOf(HttpStatus status) {
            return status.series;
        }

        public static Series valueOf(int statusCode) {
            Series series = resolve(statusCode);
            if (series == null) {
                throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
            } else {
                return series;
            }
        }

        @Nullable
        public static Series resolve(int statusCode) {
            int seriesCode = statusCode / 100;
            Series[] var2 = values();
            int var3 = var2.length;

            for (Series series : var2) {
                if (series.value == seriesCode) {
                    return series;
                }
            }

            return null;
        }
    }


}
